package com.falcon.mvc.auto;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zongf
 * @date 2024-02-04
 **/
@Slf4j
@Component
public class MvcConfig implements WebMvcConfigurer {

//    @Autowired
//    private RequestIdInterceptor requestIdInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        WebMvcConfigurer.super.addInterceptors(registry);

        // 注册全局请求拦截器
//        registry.addInterceptor(requestIdInterceptor).addPathPatterns("/**");

    }

    // 跨域问题, request Headers中出现: Referrer Policy: strict-origin-when-cross-origin
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
